//表单验证
$(function(){
	$('#savePasswordBtn').click(function () {
		//获取验证器
		var oldPassword = $('#old_password').val();
		var newPassword = $('#new_password').val();
		var reNewPassword = $('#re_new_password').val();
		if(oldPassword == null || oldPassword == ""){
			layer.msg("旧密码不能为空!",{icon:2,time:2000});
			return;
		}
		if(!isCode(oldPassword)){
			layer.msg("亲,密码只能是英文字母和数字组合,不区分大小写哦!",{icon:2,time:2000});
			return;
		}
		if(newPassword == null || newPassword == ""){
			layer.msg("新密码不能为空!",{icon:2,time:2000});
			return;
		}
		if(!isCode(newPassword)){
			layer.msg("亲,新密码只能是英文字母和数字组合,不区分大小写哦!",{icon:2,time:2000});
			return;
		}
		if(newPassword.length < 6){
			layer.msg("新密码请输入至少6位!",{icon:2,time:2000});
			return;
		}
		if(reNewPassword == null || reNewPassword == ""){
			layer.msg("确认密码不能为空!",{icon:2,time:2000});
			return;
		}
		
		if(reNewPassword != newPassword){
			layer.msg("两次密码输入不一致!",{icon:2,time:2000});
			return;
		}
		var user = {};
		user["pwd"] = oldPassword;
		user["repwd"] = newPassword;
		$('#savePasswordBtn').attr("disabled",true);
		$.ajax({
			url:baselocation+'/password',
			contentType:'application/json',
			type:'post',
			dataType:'json',
			data: JSON.stringify(user),
			success:function(result){
				$('#savePasswordBtn').attr("disabled",false);
				if(result.success==false){
					layer.msg(result.message,{icon:2,time:2000});
				}else{
					layer.msg(result.message,{icon:1,time:2000});
					setTimeout(goToLogin, 5000);
				}
			},
			error:function(result){
				alert("系统异常,请联系管理员！");
			}
		});
	})
	//跳转登录页
	function goToLogin(){
		window.location.href=baselocation+'/login';
	}
});